<?php
class MediaController extends Zend_Controller_Action
{

    private $user_login;

    private $user_id;

    function init () {
        $this->user_id = Zend_Auth::getInstance()->getIdentity()->id;
        $this->user_login = Zend_Auth::getInstance()->getIdentity()->login;
        
        $init = new Model_Init($this);
    }

    function indexAction () {

    }

    function videoAction () {
        $model_video = new Model_Video();
        $model_video->sendToQueue();
    }

    function audioAction () {
        
        $user_request = $this->_getParam("request");
        
        if(!$user_request)$user_request = $this->user_login;
        //upload photo
        $form = new Form_Audio();
        $model_media = new Model_Media($this->user_login);
        
        $this->view->form = $form;
        $this->view->user_login = $user_request;
        $this->view->user = $this->user_login;
        
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()
                ->getPost())) {
                
                //create folder with user name
                //TODO create that folder on user registration
                $model_media->createFolder(
                "audio");
                
                $file = $form->audio->getFileInfo();
                
                $audio_name = $file['audio']['name'];
                
                $audio_name = $model_media->filter($audio_name);
                
                //TODO try without it
                //                $audio_name = $model_media->filterName($audio_name);
                

                $ready_file_path = realpath(dirname('.')) . DIRECTORY_SEPARATOR .
                 'media_data' . DIRECTORY_SEPARATOR . $this->user_login .
                 DIRECTORY_SEPARATOR . "audio" . DIRECTORY_SEPARATOR .
                 $audio_name;
                
                $form->audio->addFilter('Rename', $ready_file_path);
                
                $form->audio->receive();
                
                echo $this->view->translate('Audio was uploaded');
                
                //add action that user add new photo to album
                $model_action = new Model_Action();
                $model_action->addAction($this->user_id, 5, $audio_name);
            }
        }
        
        $this->view->audio = $model_media->getDirList("audio", $user_request);
    }

    function audioremoveAction () {
        $audio = $this->_getParam("request");
        $model_media = new Model_Media($this->user_login);
        
        $model_media->removeSong($audio, "audio");
        
        $this->_helper->redirector('audio', 'media');
    }
}









